package cn.hnbjx.prepaid.service;

import cn.hnbjx.prepaid.common.BusinessException;
import cn.hnbjx.prepaid.common.BusinessStatus;
import cn.hnbjx.prepaid.dao.AccountDao;
import cn.hnbjx.prepaid.pojo.Account;
import cn.hnbjx.prepaid.utils.ShareUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

import static java.time.LocalDate.now;

@Slf4j
@Service
public class AccountService {
    @Autowired
    private AccountDao accountDao;

    public Account findAccountById(String openId) {
        log.info("openid: {}",openId);
        return accountDao.findAccountById(openId);
    }
    public Account findAccountById2(String openId) {
        log.info("openid: {}",openId);
        return accountDao.findAccountById(openId);
    }


    public PageInfo<Account> getAccount(int page,String key) {
        PageHelper.startPage(page,10);
        List<Account> account = accountDao.getAccount(key);
        PageInfo<Account> accountPageInfo = new PageInfo<>(account);
        return accountPageInfo;
    }
    public  Integer updateAuth(String username,String tel,String token){
        return  accountDao.updateAuth(username,tel,token);
    }
    public  Integer updateUser(String name,String phone,String city,String address,String location,String token){
        return  accountDao.updateUser(name,phone,city,address,location,token);
    }
    public  Integer audit(Integer id,String remark,Integer flag,Integer audit){
        return  accountDao.updateFlag(remark,flag,audit,id);
    }

    public  List<Account> findByProvince(String key){
        return  accountDao.findByProvince(key);
    }
    public  String getCode(String openId){
        Account account=accountDao.findAccountById(openId);
        String str=account!=null?ShareUtils.id2ShareCode(account.getId()):"未登录";
        return  str;
    }


}
